package com.cheryl.springailearn.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/ai")
@RequiredArgsConstructor
class AIController {

    private final ChatClient chatClient;

    @GetMapping("/chat")
    public String chat(@RequestParam(value = "msg",defaultValue = "请将你好翻译成英语") String message) {
        //prompt:提示词
        ChatClient.ChatClientRequest.CallResponseSpec call = chatClient.prompt().user(message).call();
        String content = call.content();
        return content;
    }

    @GetMapping(value = "/chat/stream",produces="text/html;charset=UTF-8")
    public Flux<String> chatStream(@RequestParam(value = "msg",defaultValue = "请将你好翻译成英语") String message) {
        //prompt:提示词
        return chatClient.prompt().user(message).stream().content();
    }
}